package com.sw.youvote.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HTMLTable.Cell;
import com.sw.youvote.client.services.QuizServiceDelegate;

/**
 * Entry point classes define onModuleLoad().
 */
public class YouVote implements EntryPoint {
    private QuizListGUI gui;
    private QuizServiceDelegate delegate;
    
    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
        
        gui = new QuizListGUI();
        delegate = new QuizServiceDelegate();
        gui.quizService = delegate;
        delegate.setGUI(gui);
        gui.init();
        delegate.listQuizs();
        wireGUIEvents();
                
        
    }

    private void wireGUIEvents() {
    	
       gui.getContentArea().getUltimoDiaArea().getQuizGridUltimoDia().addClickHandler(new ClickHandler(){
            public void onClick(ClickEvent event) {
            Cell cellForEvent = gui.getContentArea().getUltimoDiaArea().getQuizGridUltimoDia().getCellForEvent(event);
            gui.gui_eventContactGridClicked(cellForEvent);                
    }});
        
        gui.getFormularioCreacionArea().getAddButton().addClickHandler(new ClickHandler(){
            public void onClick(ClickEvent event) {
                gui.getFormularioCreacionArea().gui_eventAddButtonClicked();
            }});

        gui.getFormularioCreacionArea().getUpdateButton().addClickHandler(new ClickHandler(){
            public void onClick(ClickEvent event) {
                gui.getFormularioCreacionArea().gui_eventUpdateButtonClicked();
            }});
        
        gui.getFormularioCreacionArea().getAddCandidatureButton().addClickHandler(new ClickHandler(){
            public void onClick(ClickEvent event) {
                gui.getFormularioCreacionArea().gui_eventAddCandidatureButtonClicked();
            }});
        
        gui.getSidebarArea().getAddNewButton().addClickHandler(new ClickHandler(){
            public void onClick(ClickEvent event) {
                gui.getSidebarArea().gui_eventAddNewButtonClicked();
                
            }});
        
        gui.getFormularioCreacionArea().getAddCandidatureForm().getCandidatureButton().addClickHandler(new ClickHandler(){
            public void onClick(ClickEvent event) {
                gui.getFormularioCreacionArea().getAddCandidatureForm().gui_eventCandidatureButtonClicked();
                
            }});

    }
}
